package alfred.mdp.messages.worker;

import alfred.mdp.Majordomo;
import alfred.mdp.messages.ProtocolMessage;
import org.zeromq.ZMsg;

import static alfred.mdp.utils.Utils.asString;

/**
 * Ready <br>
 * Frame 0: Empty frame<br>
 * Frame 1: "MDPW01" (six bytes, representing MDP/Worker v0.1)<br>
 * Frame 2: 0x01 (one byte, representing READY)<br>
 * Frame 3: Service name (printable string)<br>
 */
public class Ready extends ProtocolMessage {

    public Ready(String service) {
        super(
                Majordomo.EMPTY,
                Majordomo.PROTOCOL_WORKER_V,
                Majordomo.Worker.READY,
                asZFrame(service)
        );
    }

    public Ready(ZMsg received) {
        super(getSubMsg(received, 1));
        setClientId(get(received, 0));
    }

    @Override
    public String getServiceName() {
        return asString(get(3).getData());
    }
}
